//
//  MallBuyTogetherTableViewCell.m
//  CYWFrame
//
//  Created by 于顺燊 on 2018/9/10.
//  Copyright © 2018年 Macx. All rights reserved.
//

#import "MallBuyTogetherTableViewCell.h"

@implementation MallBuyTogetherTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
	self.face.layer.cornerRadius = self.face.height/2;
	self.face.clipsToBounds = YES;;
    // Initialization codex
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)joinBtnClick:(id)sender {
	[self.delegate joinTogether:sender :self.model.ecbuy_id :self.model.user_id];
}

- (void)setModel:(MallDetailBuyTogetherModel *)model
{
	if (_model != model) {
		_model = model;
		[self.face sd_setImageWithURL:[NSURL URLWithString:model.face]];
		self.nickname.text = model.nickname;
		self.surplus_people.text = [NSString stringWithFormat:@"还差%ld人拼单",(long)model.surplus_people];
		[self countTimeLeft];
	}
}

- (void)countTimeLeft
{
	//时间戳转时间
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:@"HH:mm:ss"];
	
	NSTimeInterval endTime = [self.model.end_time doubleValue];
	NSTimeInterval nowTime = [[NSDate date] timeIntervalSince1970];
	NSTimeInterval difference = endTime - nowTime;
	int second = (int)difference %60;//秒
	int minute = (int)difference /60%60;
	int hour = (int)difference / 3600;
	//int day = (int)difference / (24 *3600);
	NSString *leftStr = [NSString stringWithFormat:@"%d:%d:%d", hour, minute, second];
	
	self.surplus_time.text = leftStr;
}

@end
